from pysqlite2 import dbapi2 as sqlite

dbname = 'database_test_11'

db = sqlite.connect(dbname)

query = 'update link set flag=0'
db.execute(query)
db.commit()

query = "update link set flag=1 where toid not in (select distinct fromid from link)"
db.execute(query)
db.commit()
